package com.yanqu.road.dao.impl.admin;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.admin.AdminInnerBuyOrderData;
import com.yanqu.road.entity.beautyescort.EscortServerGroup;
import com.yanqu.road.entity.config.goods.GoodsBagInfo;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.cricket.config.CricketCourtConfig;
import com.yanqu.road.entity.decoration.MammonTypeSwitch;
import com.yanqu.road.entity.mall.ShieldMallMarkIdData;
import com.yanqu.road.entity.servercenter.*;
import com.yanqu.road.entity.servercenter.group.CricketServerGroup;
import com.yanqu.road.entity.servercenter.group.CrossMarriageGroup;
import com.yanqu.road.entity.servercenter.tabnotice.ChannelTabNotice;
import com.yanqu.road.entity.servercenter.whitelist.WhiteAccount;
import com.yanqu.road.entity.servercenter.whitelist.WhiteIP;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupRule;
import com.yanqu.road.entity.union.cross.CrossUnionServerGroup;
import com.yanqu.road.entity.union.huaben.UnionHuaBenServerGroup;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.*;
import java.util.Date;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class AdminCommonDaoImpl extends TempDao {

    public int getChannelNoticeMaxId(int channelId) {
        String sql = "select ifnull(max(id),1) as maxId from `t_s_notice` where `channelId`=?";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchUpdateChannelNotice(List<ChannelNotice> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_notice`(channelId,id,languageType,content,title) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ChannelNotice channelNotice : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelNotice.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, channelNotice.getId()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getLanguage()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getContent()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getTitle()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateChannelAppNotice(List<ChannelNotice> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_appid_notice`(appId,languageType,content,title) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ChannelNotice channelNotice : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getAppId()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getLanguage()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getContent()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getTitle()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateChannelAppNotice20(List<ChannelNotice> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_appid_notice`(appId,languageType,content,title,gameType) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ChannelNotice channelNotice : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getAppId()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getLanguage()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getContent()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelNotice.getTitle()));
            para.put(i++, new DbParameter(Types.INTEGER, 1));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateSeverState(List<ServerInfo> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "update `t_s_server_list` set state=? where serverId=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ServerInfo data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getServerId()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateSeverInfo(List<ServerInfo> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "update `t_s_server_list` set channelId=?,markStr=?,serverName=?,isOpen=?,state=?,openTime=?,openSplitFlow=?,createRoleCountLimit=? where serverId=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ServerInfo data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getMarkStr()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getServerName()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isOpen()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOpenTime()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isOpenSplitFlow()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCreateRoleCountLimit()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getServerId()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateServerInfo(ServerInfo data) {
        String sql = "update `t_s_server_list` set channelId=?,serverType=?,markStr=?,serverName=?,isOpen=?,state=?,openTime=?,openSplitFlow=?,createRoleCountLimit=?,openZsDay=?,specialServer=?,createPreRoleNum=?,specialServerParam=? where serverId=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getServerType()));
        para.put(i++, new DbParameter(Types.VARCHAR, data.getMarkStr()));
        para.put(i++, new DbParameter(Types.VARCHAR, data.getServerName()));
        para.put(i++, new DbParameter(Types.BOOLEAN, data.isOpen()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
        para.put(i++, new DbParameter(Types.BIGINT, data.getOpenTime()));
        para.put(i++, new DbParameter(Types.BOOLEAN, data.isOpenSplitFlow()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getCreateRoleCountLimit()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getOpenZsDay()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getSpecialServer()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getCreatePreRoleNum()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getSpecialServerParam()));
        para.put(i++, new DbParameter(Types.BIGINT, data.getServerId()));

        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public AdminInnerBuyOrderData getAdminInnerBuyOrderData(String orderId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String getAdminInnerBuyOrderDataSql = "select * from `t_s_inner_user_buy_order` where `orderId`=?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getAdminInnerBuyOrderDataSql);
            int i = 1;
            call.setString(i++, orderId);
            rs = call.executeQuery();
            if (rs.next()) {
                return parseOrderData(rs);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return null;
    }

    public boolean addOrderData(AdminInnerBuyOrderData adminInnerBuyOrderData) {
        String insertAdminInnerBuyOrderDataSql = "insert into `t_s_inner_user_buy_order`(orderId,orderTime) values (?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.VARCHAR, adminInnerBuyOrderData.getOrderId()));
        para.put(i++, new DbParameter(Types.BIGINT, adminInnerBuyOrderData.getOrderTime()));
        if (getDb().executeNoneQuery(insertAdminInnerBuyOrderDataSql, para) > 0) {
            return true;
        }
        return false;
    }

    protected AdminInnerBuyOrderData parseOrderData(ResultSet rs) throws SQLException {
        AdminInnerBuyOrderData adminInnerBuyOrderData = new AdminInnerBuyOrderData();
        adminInnerBuyOrderData.setOrderId(rs.getString("orderId"));
        adminInnerBuyOrderData.setOrderTime(rs.getLong("orderTime"));

        return adminInnerBuyOrderData;
    }


    public boolean updateActivityInfo(long importBatch, long beginTime, long beginShowTime, long endTime, long endShowTime) {
        String sql = "update `t_s_activity_main` set beginTime=?,beginShowTime=?,endTime=?,endShowTime=? where importBatch=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(beginTime)));
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(beginShowTime)));
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(endTime)));
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(endShowTime)));
        para.put(i++, new DbParameter(Types.BIGINT, importBatch));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchUpdateActivityIgnore(List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_system_activity_ignore`(activityId,state,serverId,dealTime,noticeTime) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, map.get("activityId")));
            para.put(i++, new DbParameter(Types.INTEGER, map.get("state")));
            para.put(i++, new DbParameter(Types.BIGINT, 0L));
            para.put(i++, new DbParameter(Types.INTEGER, DateHelper.getCurrentSecond()));
            para.put(i++, new DbParameter(Types.INTEGER, 0));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public List<Integer> getBatchActivityId(int type, int childType,Set<Long> serverIdSet) {
        String sql = "select activityId,serverList from t_s_activity_main where type = ? and childType = ? and endShowTime > ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, type);
            call.setInt(i++, childType);
            call.setString(i++, DateHelper.getCurrentDateTimeString());
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("activityId"));
                List<Long> serverList = StringUtils.stringToLongList(rs.getString("serverList"), ",");
                serverIdSet.addAll(serverList);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<Integer> getBatchActivityId(long importBatch, Set<Long> serverIdSet) {
        String sql = "select activityId,serverList from t_s_activity_main where importBatch = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setLong(i++, importBatch);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("activityId"));
                List<Long> serverList = StringUtils.stringToLongList(rs.getString("serverList"), ",");
                serverIdSet.addAll(serverList);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<Integer> getMailState(long personalId, long userId) {
        String sql = "select isRead,isGetReward from t_u_mail where receiveUserId = ? and personalId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getUserDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setLong(i++, userId);
            call.setLong(i++, personalId);
            rs = call.executeQuery();
            if (rs.next()) {
                int isRead = rs.getInt("isRead");
                int isGetReward = rs.getInt("isGetReward");
                list.add(isRead);
                list.add(isGetReward);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<Integer> getDeletedMailState(long personalId, long userId) {
        String sql = "select isRead,isGetReward from t_l_delete_mail where receiveUserId = ? and personalId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getLogDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setLong(i++, userId);
            call.setLong(i++, personalId);
            rs = call.executeQuery();
            if (rs.next()) {
                int isRead = rs.getInt("isRead");
                int isGetReward = rs.getInt("isGetReward");
                list.add(isRead);
                list.add(isGetReward);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }


    public boolean updatePlatformPolicy(PlatformPolicy platformPolicy) {
        String sql = "replace into `t_s_platform_policy`(channelId,userAgreement,privacyPolicy) values (?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, platformPolicy.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, platformPolicy.getUserAgreement()));
        para.put(i++, new DbParameter(Types.VARCHAR, platformPolicy.getPrivacyPolicy()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }


    public int getPlatformMaxGoodsId(int channelId) {
        String sql = "select ifnull(max(id),0) as maxId from `t_s_platform_goods` where `channelId`=?";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 0;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean insertPlatformGoods(Map<String, Object> paramsMap) {
        String sql = "insert into `t_s_platform_goods`(id,`type`,`quality`,`name`,`desc`,`params`,`icon`,`extendParam`,mailTitle,mailContent,gameType,channelId,canUse,canBagUse) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("id")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("type")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("quality")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("name")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("desc")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("params")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("icon")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("extendParam")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("mailTitle")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("mailContent")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("gameType")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("channelId")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("canUse")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("canBagUse")));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean updatePlatformGoods(Map<String, Object> paramsMap) {
        String sql = "update `t_s_platform_goods` set `type`=?,`quality`=?,`name`=?,`desc`=?,`params`=?,`icon`=?,extendParam=?,mailTitle=?,mailContent=?,gameType=?,channelId=? where id = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("type")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("quality")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("name")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("desc")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("params")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("icon")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("extendParam")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("mailTitle")));
        para.put(i++, new DbParameter(Types.VARCHAR, paramsMap.get("mailContent")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("gameType")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("channelId")));
        para.put(i++, new DbParameter(Types.INTEGER, paramsMap.get("id")));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deletePlatformGoods(int channelId, int boxId) {
        String sql = "delete from t_s_platform_goods where id=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, boxId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public Map<String, Object> getPlatformGoods(int channelId, int goodsId) {
        String sql = "select * from t_s_platform_goods where channelId = ? and id = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<String, Object> map = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            call.setInt(i++, goodsId);
            rs = call.executeQuery();
            while (rs.next()) {
                map.put("mailTitle", rs.getString("mailTitle"));
                map.put("mailContent", rs.getString("mailContent"));
                map.put("id", rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    //商会分组
    public int getCrossUnionGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_cross_union_server_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertCrossUnionServerGroup(List<CrossUnionServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_cross_union_server_group`(groupId,state,channelId,serverList) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (CrossUnionServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossUnionServerGroup(CrossUnionServerGroup data) {
        String sql = "update `t_s_cross_union_server_group` set state=?,channelId=?,serverList=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteUnionServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_cross_union_server_group where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteUnionServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_cross_union_server_group where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    //配置
    public List<HashMap<String, Object>> getChannelConfig(int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<HashMap<String, Object>> list = new ArrayList<>();
        String sql = "select * from t_s_param where channelId = ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                HashMap<String, Object> dataMap = new HashMap<>();
                String param = rs.getString("param");
                String value = rs.getString("value");
                String remark = rs.getString("description");
                int cid = rs.getInt("channelId");
                dataMap.put("channelId", cid);
                dataMap.put("param", param);
                dataMap.put("value", value);
                dataMap.put("remark", remark);
                list.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public boolean deleteChannelConfig(int channelId, String param) {
        String sql = "delete from t_s_param where channelId=? and param=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, param));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateChannelConfig(int channelId, String param, String value, String remark) {
        String sql = "update t_s_param set `value`=?,`description`=? where channelId=? and param=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.VARCHAR, value));
        para.put(i++, new DbParameter(Types.VARCHAR, remark));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, param));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean addChannelConfig(int id, int channelId, String param, String value, String remark) {
        String sql = "insert into t_s_param(`id`, `channelId`, `param`, `value`,`description`)values(?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, id));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, param));
        para.put(i++, new DbParameter(Types.VARCHAR, value));
        para.put(i++, new DbParameter(Types.VARCHAR, remark));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public int getCrossBanquetMarriageGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_marriage_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public int getChannelConfigMaxId() {
        String sql = "select ifnull(max(id),0) as maxId from `t_s_param` ";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    //宴会分组
    public boolean batchInsertCrossBanquetMarriageServerGroup(List<CrossMarriageGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_marriage_group`(groupId,isCrossMarriage,isCrossBanquet,changTime,channelId,serverList) values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (CrossMarriageGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isCrossMarriage()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isCrossBanquet()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChangTime()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossBanquetMarriageServerGroup(CrossMarriageGroup data) {
        String sql = "update `t_s_marriage_group` set isCrossMarriage=?,isCrossBanquet=?,changTime=?,channelId=?,serverList=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.BOOLEAN, data.isCrossMarriage()));
        para.put(i++, new DbParameter(Types.BOOLEAN, data.isCrossBanquet()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getChangTime()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteBanquetMarriageServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_marriage_group where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteBanquetMarriageServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_marriage_group where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }


    //押镖分组
    public int getCrossEscortServerGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_escort_server_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertEscortServerGroup(List<EscortServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_escort_server_group`(groupId,escortState,channelId,serverList) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (EscortServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getEscortState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossEscortServerGroup(EscortServerGroup data) {
        String sql = "update `t_s_escort_server_group` set escortState=?,channelId=?,serverList=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.getEscortState()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteEscortServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_escort_server_group where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteEscortServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_escort_server_group where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchInsertCrossEscortServerGroup(List<EscortServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_escort_server_group`(groupId,escortState,channelId,serverList) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (EscortServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getEscortState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    //话本
    public int getCrossHuaBenGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_union_hua_ben_server_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertHuaBenServerGroup(List<UnionHuaBenServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_union_hua_ben_server_group`(groupId,`state`,channelId,serverList) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (UnionHuaBenServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossHuaBenServerGroup(UnionHuaBenServerGroup data) {
        String sql = "update `t_s_union_hua_ben_server_group` set `state`=?,channelId=?,serverList=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
        para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteHuaBenServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_union_hua_ben_server_group where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteHuaBenServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_union_hua_ben_server_group where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchInsertCrossHuaBenServerGroup(List<UnionHuaBenServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_union_hua_ben_server_group`(groupId,`state`,channelId,serverList) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (UnionHuaBenServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    //微信白名单
    //t_s_wechat_rank_black_user
    public boolean batchInsertWechatRankBlankUser(int channelId, List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_wechat_rank_black_user`(openId,`channelId`,`owner`) values (?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("openId")));
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("remark")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateWechatRankBlankUser(int channelId, List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "update `t_s_wechat_rank_black_user` set `channelId`=?,`owner`=? where openId = ?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("remark")));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("openId")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchDeleteWechatRankBlankUser(int channelId, List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "delete from `t_s_wechat_rank_black_user` where openId = ?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("openId")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public List<HashMap<String, Object>> getWechatBlackUserList(int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<HashMap<String, Object>> list = new ArrayList<>();
        String sql = "select * from t_s_wechat_rank_black_user where channelId = ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                HashMap<String, Object> dataMap = new HashMap<>();
                String openId = rs.getString("openId");
                String owner = rs.getString("owner");
                dataMap.put("openId", openId);
                dataMap.put("remark", owner);
                list.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public boolean batchUpdateSpecialSeverInfo(List<ServerInfo> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "update `t_s_server_list` set specialServerParam=? where serverId=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ServerInfo data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getSpecialServerParam()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getServerId()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateSpecialSeverInfo(ServerInfo serverInfo) {

        boolean result = false;
        String sql = "update `t_s_server_list` set specialServerParam=? where serverId=?";

        getDb().setConnName(DbNameStrategy.getServerDb());

        Map<Integer, DbParameter> para = new HashMap<>();
        int i = 1;
        para.put(i++, new DbParameter(Types.INTEGER, serverInfo.getSpecialServerParam()));
        para.put(i++, new DbParameter(Types.BIGINT, serverInfo.getServerId()));

        if (getDb().executeNoneQuery(sql, para) > -1) {
            result = true;
        }
        return result;
    }

    public List<UnionActivityGroupRule> getUnionActivityGroupRuleList() {
        List<UnionActivityGroupRule> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from `t_s_union_activity_group_rule` where expireTime>? or expireTime=0";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setLong(i++, System.currentTimeMillis());
            rs = call.executeQuery();
            while (rs.next()) {
                UnionActivityGroupRule unionActivityGroupRule = new UnionActivityGroupRule();
                unionActivityGroupRule.setActivityType(rs.getInt("activityType"));
                unionActivityGroupRule.setChildType(rs.getInt("childType"));
                unionActivityGroupRule.setUnionUid1(rs.getString("unionUid1"));
                unionActivityGroupRule.setUnionUid2(rs.getString("unionUid2"));
                unionActivityGroupRule.setExpireTime(rs.getLong("expireTime"));
                unionActivityGroupRule.setRemark(rs.getString("remarks"));
                unionActivityGroupRule.setId(rs.getInt("id"));
                list.add(unionActivityGroupRule);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public boolean batchDeleteUnionActivityGroupRule(List<String> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "delete from `t_s_union_activity_group_rule` where unionUid1 = ?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (String data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, data));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean deleteUnionActivityGroupRuleById(List<Integer> list) {
        if (list.size() == 0) {
            return false;
        }
        boolean result = false;
        String sql = "delete from `t_s_union_activity_group_rule` where id in (" + StringUtils.listToString(list, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<>();
        if (getDb().executeNoneQuery(sql, para) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchInsertUnionActivityGroupRule(List<UnionActivityGroupRule> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_union_activity_group_rule`(activityType,childType,unionUid1,unionUid2,remarks) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (UnionActivityGroupRule data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChildType()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getUnionUid1()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getUnionUid2()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRemark()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public Map<Integer, Map<String, Object>> getGrandChildGroupConfigMap(int channelId) {
        String selectSql = "select * from `t_s_grand_child_group_config` where channelId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, Map<String, Object>> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(selectSql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                int groupId = rs.getInt("groupId");
                int state = rs.getInt("state");
                int changTime = rs.getInt("changTime");
                int autoId = rs.getInt("autoId");
                String serverListStr = rs.getString("serverList");
                List<Long> serverList = StringUtils.stringToLongList(serverListStr, ",");
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("groupId", groupId);
                dataMap.put("state", state);
                dataMap.put("changTime", changTime);
                dataMap.put("autoId", autoId);
                dataMap.put("serverList", serverList);
                map.put(groupId, dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    public int getCrossGrandChildServerGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_grand_child_group_config`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertGrandChildServerGroup(List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_grand_child_group_config`(groupId,state,channelId,serverList,changTime,autoId) values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.get("groupId")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("state")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("channelId")));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString((List)data.get("serverList"), ",")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("changTime")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("autoId")));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossGrandChildServerGroup(Map<String, Object> data) {
        String sql = "update `t_s_grand_child_group_config` set state=?,channelId=?,serverList=?,changTime=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.get("state")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("channelId")));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString((List)data.get("serverList"), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("changTime")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("groupId")));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteGrandChildServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_grand_child_group_config where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteGrandChildServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_grand_child_group_config where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public Map<Integer, Map<String, Object>> getServerGroup2Map(int channelId) {
        String selectSql = "select * from `t_s_server_group2` where channelId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, Map<String, Object>> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(selectSql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                int groupType = rs.getInt("groupType");
                int groupId = rs.getInt("groupId");
                int openStatus = rs.getInt("openStatus");
                int changTime = rs.getInt("changTime");
                String serverListStr = rs.getString("serverList");
                List<Long> serverList = StringUtils.stringToLongList(serverListStr, ",");
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("groupId", groupId);
                dataMap.put("openStatus", openStatus);
                dataMap.put("changTime", changTime);
                dataMap.put("groupType", groupType);
                dataMap.put("serverList", serverList);
                map.put(groupId, dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    public int getCrossServerGroup2MaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_server_group2`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertServerGroup2(List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_server_group2`(groupId,openStatus,channelId,serverList,changTime,groupType) values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.get("groupId")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("openStatus")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("channelId")));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString((List)data.get("serverList"), ",")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("changTime")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("groupType")));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean updateCrossServerGroup2(Map<String, Object> data) {
        String sql = "update `t_s_server_group2` set openStatus=?,channelId=?,serverList=?,changTime=?,groupType=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.get("openStatus")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("channelId")));
        para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString((List)data.get("serverList"), ",")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("changTime")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("groupType")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("groupId")));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteServerServerGroup2(int groupId, int channelId) {
        String sql = "delete from t_s_server_group2 where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteServerGroup2(List<Integer> channelIdList) {
        String sql = "delete from t_s_server_group2 where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchInsertMammonTypeSwitch(List<MammonTypeSwitch> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_mammon_type_switch`(channelId,decorationId,openStatus) values (?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (MammonTypeSwitch data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDecorationId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOpenStatus()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateMammonTypeSwitch(List<MammonTypeSwitch> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "update `t_s_mammon_type_switch` set `openStatus`=?  where channelId = ? and `decorationId`=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (MammonTypeSwitch data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getOpenStatus()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getDecorationId()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean deleteMammonTypeSwitchList(int channelId) {
        String sql = "delete from t_s_mammon_type_switch where channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public Map<Integer, ServerGroup> getServerGroupMap(int channelId) {
        String selectSql = "select * from `t_s_server_group` where channelId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, ServerGroup> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(selectSql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                ServerGroup data = new ServerGroup();
                data.setGroupId(rs.getInt("groupId"));
                data.setChannelId(rs.getInt("channelId"));
                data.setCrossChat(rs.getBoolean("crossChat"));
                data.setCrossRank(rs.getBoolean("crossRank"));
                data.setCrossMammonState(rs.getInt("crossMammon"));
                String value = rs.getString("serverList");
                if(!StringUtils.isNullOrEmpty(value)){
                    data.setServerListStr(value);
                }
                data.setServerList(StringUtils.stringToLongList(data.getServerListStr(), ","));
                map.put(data.getGroupId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    public int getCrossServerGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_server_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean batchInsertServerGroup(List<ServerGroup> list, int changTime) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_server_group`(groupId,crossChat,channelId,serverList,crossRank,crossMammon,changTime) values (?,?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ServerGroup data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.isCrossChat() ? 1 : 0));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getServerListStr()));
            para.put(i++, new DbParameter(Types.INTEGER, data.isCrossRank() ? 1 : 0));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCrossMammonState()));
            para.put(i++, new DbParameter(Types.INTEGER, changTime));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchDeleteChannelGoods(List<Map<String, Object>> list, int channelId) {
        String sql = "delete from t_s_goods_channel where channelId=? and `addType` <> 1";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchUpdateChannelGoods(List<Map<String, Object>> list, int channelId) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
//        String sql = "replace into `t_s_goods_channel`(channelId,id,`type`,`quality`,`canUse`,`maxNum`,`sort`,`params`,`name`,`desc`,`icon`,`getWay`,`extendParam`,`resourceParam`,`isHidden`,`canBagUse`,`addType`,`recyclingType`,`area`) " +
//                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        String sql = "insert into `t_s_goods_channel`(channelId,id,`name`,`desc`,`quality`,`type`,`params`,`extendParam`, `sort`, `canUse`,`maxNum`,`recyclingType`,`icon`,`isHidden`,`canBagUse`,`getWay`) " +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("id"))));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("name")));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("desc")));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("quality"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("type"))));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("params")));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("extendParam")));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("sort"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("canUse"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("maxNum"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("recyclingType"))));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("icon")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("isHidden")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("canBagUse")));
            para.put(i++, new DbParameter(Types.INTEGER, data.get("getWay")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchDeleteChannelBagGoods(List<Map<String, Object>> list, int channelId) {
//        String sql = "delete from t_s_goods_bag_channel where channelId=? and `addType` <> 1 and type not in(1,2,3,4)";
        String sql = "delete from t_s_goods_bag_channel where channelId=? and `addType` <> 1";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchUpdateChannelBagGoods(List<Map<String, Object>> list, int channelId) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_goods_bag_channel`(`channelId`, `id`, `boxId`, `itemId`, `minNum`, `maxNum`, `randomType`, `probability`, `isNotice`, `addType`) " +
                "values (?,?,?,?,?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("id"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("boxId"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("itemId"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("minNum"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("maxNum"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("randomType"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("probability"))));
            para.put(i++, new DbParameter(Types.INTEGER, Integer.parseInt((String)data.get("isNotice"))));
            //注意
            para.put(i++, new DbParameter(Types.INTEGER, 0));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchDeleteChannelLanguage(List<Map<String, Object>> list, int channelId) {
        String sql = "delete from t_s_language_channel where channelId=? and type not in(1,2,3,4)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchUpdateChannelLanguage(List<Map<String, Object>> list, int channelId) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_language_channel`(`channelId`,  `key`, `language`, `content`, `type`, `f_id`) " +
                "values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("key")));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("language")));
            para.put(i++, new DbParameter(Types.VARCHAR, data.get("content")));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOrDefault("type", 0)));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOrDefault("f_id", 0)));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public int getChannelBrocadeBoxMaxId(int channelId) {
        String sql = "select ifnull(max(id),0) as maxId from `t_s_goods_channel` where `channelId`=? ";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public int getChannelBrocadeBoxItemMaxId(int channelId) {
        String sql = "select ifnull(max(id),0) as maxId from `t_s_goods_bag_channel` where `channelId`=? or `channelId`=0";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public int selectBrocadeByName(int channelId, String name){
        String sql = "select id from t_s_goods_channel where `name` = ?  and `channelId` = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        int id = 0;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setString(i++, name);
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            if (rs.next()) {
                id = rs.getInt("id");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return id;
    }


    public boolean addBrocade(int channelId, GoodsInfo goodsInfo, List<GoodsBagInfo> childList, List<Map<String, Object>> languageList) {

        Connection connection = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            connection = getDb().getConnection();
            connection.setAutoCommit(false);

            String sql = "insert into `t_s_goods_channel`(`id`,`type`,`quality`,`canUse`,`maxNum`,`name`,`desc`,`icon`,`channelId`,`addType`,`extendParam`,`area`, `canBagUse`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";

            int i = 1;
            Map<Integer, DbParameter> para = new HashMap<>();
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getGoodsId()));
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getQuality()));
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getCanUse()));
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getTopLimit()));
            para.put(i++, new DbParameter(Types.VARCHAR, goodsInfo.getGoodsName()));
            para.put(i++, new DbParameter(Types.VARCHAR, goodsInfo.getGoodsDesc()));
            para.put(i++, new DbParameter(Types.VARCHAR, goodsInfo.getIcon()));
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            para.put(i++, new DbParameter(Types.INTEGER, 1));
            para.put(i++, new DbParameter(Types.VARCHAR, ""));
            para.put(i++, new DbParameter(Types.INTEGER, goodsInfo.getArea()));
            para.put(i++, new DbParameter(Types.BOOLEAN, goodsInfo.isCanBagUse()));

            PreparedStatement pstmt = connection.prepareStatement(sql);
            for (Map.Entry<Integer, DbParameter> entry : para.entrySet()) {
                pstmt.setObject(entry.getKey(), entry.getValue().getResult());
            }
            int ret = pstmt.executeUpdate();
            pstmt.clearParameters();
            if(ret <= 0){
                return false;
            }

            sql = "insert into `t_s_goods_bag_channel`(`id`,`boxId`,`itemId`,`minNum`,`maxNum`,`randomType`,`probability`,`channelId`,`addType`) values (?,?,?,?,?,?,?,?,?)";

            List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
            for (GoodsBagInfo data: childList) {
                para = new HashMap<>();
                i = 1;
                para.put(i++, new DbParameter(Types.INTEGER, data.getId()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getBagId()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getGoodsId()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getMinNum()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getMaxNum()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getRandomType()));
                para.put(i++, new DbParameter(Types.INTEGER, data.getRandomWeight()));
                para.put(i++, new DbParameter(Types.INTEGER, channelId));
                para.put(i++, new DbParameter(Types.INTEGER, 1));
                mapList.add(para);
            }

            pstmt = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            for (Map<Integer, DbParameter> map : mapList) {
                for (Map.Entry<Integer, DbParameter> entry : map.entrySet()) {
                    pstmt.setObject(entry.getKey(), entry.getValue().getResult());
                }
                pstmt.addBatch();
            }
            int[] rets = pstmt.executeBatch();
            pstmt.clearParameters();
            for (int ret1 : rets) {
                if(ret1 <= 0){
                    return false;
                }
            }

            sql = "insert into `t_s_language_channel`(`key`,`language`,`content`,`channelId`,`type`,`f_id`) values (?,?,?,?,?,?)";

            mapList = new ArrayList<>();
            for (Map<String, Object> data: languageList) {
                para = new HashMap<>();
                i = 1;
                if(data.get("key") == null){
                    continue;
                }
                para.put(i++, new DbParameter(Types.VARCHAR, data.get("key")));
                para.put(i++, new DbParameter(Types.VARCHAR, data.get("language")));
                para.put(i++, new DbParameter(Types.VARCHAR, data.get("content")));
                para.put(i++, new DbParameter(Types.INTEGER, channelId));
                para.put(i++, new DbParameter(Types.INTEGER, data.get("type")));
                para.put(i++, new DbParameter(Types.VARCHAR, data.get("f_id")));
                mapList.add(para);
            }
            if(!mapList.isEmpty()){
                pstmt = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                for (Map<Integer, DbParameter> map : mapList) {
                    for (Map.Entry<Integer, DbParameter> entry : map.entrySet()) {
                        pstmt.setObject(entry.getKey(), entry.getValue().getResult());
                    }
                    pstmt.addBatch();
                }
                rets = pstmt.executeBatch();
                pstmt.clearParameters();
                for (int ret1 : rets) {
                    if(ret1 <= 0){
                        return false;
                    }
                }
            }
            connection.commit();
        }catch (Exception e) {
            logger.error(e.getMessage(), e);
            if(connection != null){
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                    logger.error(e.getMessage(), e);
                }
            }
            return false;
        }finally {
            try {
                if(connection != null) {
                    connection.setAutoCommit(true);
                }
            } catch (SQLException e) {
                logger.error(e.getMessage(), e);
            }
            getDb().closeConnection(null);
        }
        return true;
    }


    public boolean deleteChannelBrocadeBox(int boxId, int channelId) {
        String sql = "delete from t_s_goods_channel where `id`=? and channelId=? and `addType` = 1";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, boxId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteChannelBrocadeBoxItems(int boxId, int channelId) {
        String sql = "delete from t_s_goods_bag_channel where `boxId`=? and channelId=? and `addType` = 1";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, boxId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteChannelBrocadeBoxLanguage(String f_id, int channelId) {
        String sql = "delete from t_s_language_channel where `f_id` = ? and `channelId`=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.VARCHAR, f_id));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    //查询锦盒
    public List<Integer> getBroacdeBoxId(int id, int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String getAdminInnerBuyOrderDataSql = "select `id` from `t_s_goods_channel` where `id`=? and `channelId`=?";
        List<Integer> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getAdminInnerBuyOrderDataSql);
            int i = 1;
            call.setInt(i++, id);
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                result.add(rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    //查询锦盒
    public List<Integer> getBroacdeBoxId(int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String getAdminInnerBuyOrderDataSql = "select `id` from `t_s_goods_channel` where `channelId`=? and `addType`=1";
        List<Integer> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getAdminInnerBuyOrderDataSql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                result.add(rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    //查询锦盒
    public List<Integer> getBroacdeBoxId(String name, int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String getAdminInnerBuyOrderDataSql = "select `id` from `t_s_goods_channel` where `channelId`=? and `name` like ? and `addType`=1";
        List<Integer> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getAdminInnerBuyOrderDataSql);
            int i = 1;
            call.setInt(i++, channelId);
            call.setString(i++, "%" + name + "%");
            rs = call.executeQuery();
            while (rs.next()) {
                result.add(rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    //查询锦盒明细
    public Map<Integer, List<GoodsBagInfo>> getBroacdeBoxDetail(List<Integer> boxIdList, int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String getAdminInnerBuyOrderDataSql = "select * from `t_s_goods_bag_channel` where `channelId` = ? and `boxId` in (" + StringUtils.listToString(boxIdList, ",") + ")";
        Map<Integer, List<GoodsBagInfo>>  result = new HashMap<>();
        if(boxIdList.isEmpty()){
           return result;
        }
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getAdminInnerBuyOrderDataSql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                GoodsBagInfo bagInfo = new GoodsBagInfo();
                bagInfo.setBagId(rs.getInt("boxId"));
                bagInfo.setMinNum(rs.getInt("minNum"));
                bagInfo.setMaxNum(rs.getInt("maxNum"));
                bagInfo.setGoodsId(rs.getInt("itemId"));
                bagInfo.setRandomWeight(rs.getInt("probability"));
                bagInfo.setRandomType(rs.getInt("randomType"));

                if(!result.containsKey(bagInfo.getBagId())){
                    result.put(bagInfo.getBagId(), new ArrayList<>());
                }
                result.get(bagInfo.getBagId()).add(bagInfo);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    //查询锦盒多语言
    public Map<Integer, List<Map<String, Object>>> getBroacdeBoxLanuage(List<Integer> boxIdList, int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from `t_s_language_channel` where `channelId` = ? and `f_id` in (" + StringUtils.listToString(boxIdList, ",") + ")";
        Map<Integer, List<Map<String, Object>>>  result = new HashMap<>();
        if(boxIdList.isEmpty()){
            return result;
        }
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                int f_id = rs.getInt("f_id");
                String key = rs.getString("key");
                String language = rs.getString("language");
                String content = rs.getString("content");
                Map<String, Object> map = new HashMap<>();
                map.put("key", key);
                map.put("language", language);
                map.put("content", content);
                if(!result.containsKey(f_id)){
                    result.put(f_id, new ArrayList<>());
                }
                result.get(f_id).add(map);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    //查询锦盒列表
    public List<GoodsInfo> getBroacdeBoxList(int channelId, List<Integer> boxIdList) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from `t_s_goods_channel` where `channelId`=? and `id` in (" + StringUtils.listToString(boxIdList, ",") + ")";
        List<GoodsInfo> result = new ArrayList<>();
        if(boxIdList.isEmpty()){
            return result;
        }
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                GoodsInfo goodsInfo = new GoodsInfo();
                goodsInfo.setGoodsId(rs.getInt("id"));
                goodsInfo.setType(rs.getInt("type"));
                goodsInfo.setQuality(rs.getInt("quality"));
                goodsInfo.setTopLimit(rs.getInt("maxNum"));
                goodsInfo.setIcon(String.valueOf(rs.getInt("icon")));
                goodsInfo.setCanUse(rs.getInt("canUse"));
                goodsInfo.setGoodsName(rs.getString("name"));
                goodsInfo.setGoodsDesc(rs.getString("desc"));
                goodsInfo.setArea(rs.getInt("area"));
                goodsInfo.setCanBagUse(rs.getBoolean("canBagUse"));
                result.add(goodsInfo);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    public boolean updateCrossServerGroup(Map<String, Object> data, int changTime) {
        String sql = "update `t_s_server_group` set crossChat=?,channelId=?,serverList=?,changTime=?,crossRank=?,crossMammon=? where groupId = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, data.get("crossChat")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("channelId")));
        para.put(i++, new DbParameter(Types.VARCHAR, data.get("serverList")));
        para.put(i++, new DbParameter(Types.INTEGER, changTime));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("crossRank")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("crossMammon")));
        para.put(i++, new DbParameter(Types.INTEGER, data.get("groupId")));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteServerServerGroup(int groupId, int channelId) {
        String sql = "delete from t_s_server_group where groupId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteServerGroup(List<Integer> channelIdList) {
        String sql = "delete from t_s_server_group where channelId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public Map<Integer, ActivityInfo> allInTimeActivity(String time) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, ActivityInfo> dataMap = new ConcurrentHashMap<>();
        String sql = "select * from t_s_activity_main where beginShowTime <= ? AND endShowTime >= ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setString(1,time);
            call.setString(2,time);
            rs = call.executeQuery();
            while (rs.next()) {
                ActivityInfo data = new ActivityInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setType(rs.getInt("type"));
                data.setChildType(rs.getInt("childType"));
                data.setServerListStr(rs.getString("serverList"));
                if(!StringUtils.isNullOrEmpty(data.getServerListStr())){
                    data.setServerIdList(StringUtils.stringToLongList(data.getServerListStr(), ","));
                }
                dataMap.put(data.getActivityId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }


    public boolean updateChannelSystemConfig(ChannelSystemConfig systemConfig) {
        String sql = "replace into `t_s_system_config`(`channelId`,`systemId`,`param`,`value` ,`description`,`modifyTime`) values (?,?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, systemConfig.getChannelId()));
        para.put(i++, new DbParameter(Types.INTEGER, systemConfig.getSystemId()));
        para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getParam()));
        para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getValue()));
        para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getDescription()));
        para.put(i++, new DbParameter(Types.BIGINT, systemConfig.getModifyTime()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchUpdateChannelSystemConfig(List<ChannelSystemConfig> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_system_config`(`channelId`,`systemId`,`param`,`value` ,`description`,`modifyTime`) values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ChannelSystemConfig systemConfig : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, systemConfig.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, systemConfig.getSystemId()));
            para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getParam()));
            para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getDescription()));
            para.put(i++, new DbParameter(Types.BIGINT, systemConfig.getModifyTime()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public List<Integer> getBatchChannelSystemConfigId(int systemId, int channelId) {
        String sql = "select id from t_s_system_config where channelId = ?";
        if(systemId > 0) {
            sql = "select id from t_s_system_config where systemId = ? and channelId = ?";
        }
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            if(systemId > 0) {
                call.setInt(i++, systemId);
            }
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public boolean deleteSystemConfig(int channelId, List<Integer> idList) {
        String sql = "delete from t_s_system_config where channelId=? and systemId in (" + StringUtils.listToString(idList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<ChannelSystemConfig> getChannelSystemConfig(List<Integer> list) {
        if(list.isEmpty()){
            return Collections.emptyList();
        }
        ResultSet rs = null;
        CallableStatement call = null;
        List<ChannelSystemConfig> resultList = new ArrayList<>();
        String sql = "select * from t_s_system_config where id in (" + StringUtils.listToString(list, ",") + ")";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                int systemId = rs.getInt("systemId");
                int channelId = rs.getInt("channelId");
                String name = rs.getString("param");
                String value = rs.getString("value");
                long modifyTime = rs.getLong("modifyTime");
                ChannelSystemConfig data = new ChannelSystemConfig(systemId, name, value, channelId, modifyTime);
                data.setDescription(rs.getString("description"));
                resultList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }


    public boolean addChannelSystemLoopConfig(SystemLoopConfig loopConfig) {
        String sql = "insert into `t_s_system_loop_config`(`channelId`,`openDays`,`systemIds`,`modifyTime`) values (?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, loopConfig.getChannelId()));
        para.put(i++, new DbParameter(Types.VARCHAR, loopConfig.getOpenDays()));
        para.put(i++, new DbParameter(Types.VARCHAR, loopConfig.getSystemIds()));
        para.put(i++, new DbParameter(Types.BIGINT, loopConfig.getModifyTime()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }
    public boolean updateChannelSystemLoopConfig(SystemLoopConfig loopConfig) {
        String sql = "update `t_s_system_loop_config` set `systemIds`=?,`openDays`=?,`channelId` = ?, `modifyTime`= ? where `id`=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.VARCHAR, loopConfig.getSystemIds()));
        para.put(i++, new DbParameter(Types.VARCHAR, loopConfig.getOpenDays()));
        para.put(i++, new DbParameter(Types.INTEGER, loopConfig.getChannelId()));
        para.put(i++, new DbParameter(Types.BIGINT, loopConfig.getModifyTime()));
        para.put(i++, new DbParameter(Types.INTEGER, loopConfig.getId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<Integer> getBatchChannelSystemLoopConfigId(int channelId) {
        String sql = "select id from t_s_system_loop_config where channelId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("id"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<SystemLoopConfig> getChannelSystemLoopConfig(List<Integer> list) {
        if(list.isEmpty()){
            return Collections.emptyList();
        }
        ResultSet rs = null;
        CallableStatement call = null;
        List<SystemLoopConfig> resultList = new ArrayList<>();
        String sql = "select * from t_s_system_loop_config where id in (" + StringUtils.listToString(list, ",") + ")";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                int channelId = rs.getInt("channelId");
                String systemIds = rs.getString("systemIds");
                String openDays = rs.getString("openDays");
                int id = rs.getInt("id");
                long modifyTime = rs.getLong("modifyTime");
                SystemLoopConfig data = new SystemLoopConfig();
                data.setId(id);
                data.setOpenDays(openDays);
                data.setChannelId(channelId);
                data.setSystemIds(systemIds);
                data.setModifyTime(modifyTime);
                resultList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public boolean batchUpdateChannelSystemLoopConfig(List<SystemLoopConfig> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_system_loop_config`(`channelId`,`openDays`,`systemIds`,`modifyTime`) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (SystemLoopConfig systemConfig : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, systemConfig.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getOpenDays()));
            para.put(i++, new DbParameter(Types.VARCHAR, systemConfig.getSystemIds()));
            para.put(i++, new DbParameter(Types.BIGINT, systemConfig.getModifyTime()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean deleteSystemLoopConfig(int id) {
        String sql = "delete from t_s_system_loop_config where id=? ";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, id));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public int getCrossZsGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_cross_server_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean addZsGroup(int groupId, int channelId, String severIds, int isAttractInvestment) {
        String sql = "insert into `t_s_cross_server_group`(`groupId`,`channelId`,`serverList`,`crossZsState`,`changTime`) values (?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, severIds));
        para.put(i++, new DbParameter(Types.INTEGER, isAttractInvestment));
        para.put(i++, new DbParameter(Types.INTEGER, DateHelper.getCurrentSecond()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateZsGroup(int groupId, int channelId, String severIds, int isAttractInvestment) {
        String sql = "update `t_s_cross_server_group` set `channelId` = ?,`serverList`=?,`crossZsState`=?,`changTime`=?) where `groupId` = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, severIds));
        para.put(i++, new DbParameter(Types.INTEGER, isAttractInvestment));
        para.put(i++, new DbParameter(Types.INTEGER, DateHelper.getCurrentSecond()));
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<Integer> getBatchZsGroupId(int channelId) {
        String sql = "select groupId from t_s_cross_server_group where channelId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("groupId"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<CrossServerGroup> getZsServerGroup(List<Integer> list) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<CrossServerGroup> resultList = new ArrayList<>();
        String sql = "select * from t_s_cross_server_group where groupId in (" + StringUtils.listToString(list, ",") + ")";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                int channelId = rs.getInt("channelId");
                int groupId = rs.getInt("groupId");
                String serverList = rs.getString("serverList");
                int crossZsState = rs.getInt("crossZsState");
                long changTime = rs.getLong("changTime");
                CrossServerGroup data = new CrossServerGroup();
                data.setChannelId(channelId);
                data.setGroupId(groupId);
                data.setCrossZsState(crossZsState);
                data.setServerList(StringUtils.stringToLongList(serverList, ","));
                resultList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public boolean deleteZsServerGroup(int groupId) {
        String sql = "delete from t_s_cross_server_group where groupId=? ";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchAddZsServerGroup(List<CrossServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_cross_server_group`(`groupId`,`channelId`,`serverList`,`crossZsState`,`changTime`) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (CrossServerGroup data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCrossZsState()));
            para.put(i++, new DbParameter(Types.INTEGER, DateHelper.getCurrentSecond()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addCricketGroup(int groupId, int channelId, String severIds, int openStatus) {
        String sql = "insert into `t_s_cricket_group`(`groupId`,`channelId`,`serverList`,`openStatus`) values (?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, severIds));
        para.put(i++, new DbParameter(Types.INTEGER, openStatus));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateCricketGroup(int groupId, int channelId, String severIds, int openStatus) {
        String sql = "update `t_s_cricket_group` set `channelId` = ?,`serverList`=?,`openStatus`=? where `groupId` = ?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        para.put(i++, new DbParameter(Types.VARCHAR, severIds));
        para.put(i++, new DbParameter(Types.INTEGER, openStatus));
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<Integer> getBatchCricketGroupId(int channelId) {
        String sql = "select groupId from t_s_cricket_group where channelId = ?";
        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("groupId"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    public List<CricketServerGroup> getCricketServerGroup(List<Integer> list) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<CricketServerGroup> resultList = new ArrayList<>();
        String sql = "select * from t_s_cricket_group where groupId in (" + StringUtils.listToString(list, ",") + ")";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                int channelId = rs.getInt("channelId");
                int groupId = rs.getInt("groupId");
                String serverList = rs.getString("serverList");
                int openStatus = rs.getInt("openStatus");
                CricketServerGroup data = new CricketServerGroup();
                data.setChannelId(channelId);
                data.setGroupId(groupId);
                data.setOpenStatus(openStatus);
                data.setServerList(StringUtils.stringToLongList(serverList, ","));
                resultList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public boolean deleteCricketServerGroup(int groupId) {
        String sql = "delete from t_s_cricket_group where groupId=? ";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, groupId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchAddCricketServerGroup(List<CricketServerGroup> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_cricket_group`(`groupId`,`channelId`,`serverList`,`openStatus`) values (?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (CricketServerGroup data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.VARCHAR, StringUtils.listToString(data.getServerList(), ",")));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOpenStatus()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public int getCrossCricketGroupMaxId() {
        String sql = "select ifnull(max(groupId),0) as maxId from `t_s_cricket_group`";
        ResultSet rs = null;
        CallableStatement call = null;
        int maxId = 1;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            if (rs.next()) {
                maxId = rs.getInt("maxId");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return maxId;
    }

    public boolean updateCricketConfig(CricketCourtConfig courtConfig) {
        String sql = "update `t_s_cricket_court_config` SET `courtType`=?, `courtName`=?, `fightRangeServer`=?, `fightRangeDay`=?, `num`=?, `groupLimit`=?, `upNum`=?, `keepNum`=?, `reward`=?, `rankReward`=?, `courtState`=?, `modLimit`=? WHERE `courtId`=? AND `channelId`=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getCourtType()));
        para.put(i++, new DbParameter(Types.VARCHAR, courtConfig.getCourtName()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getFightRangeServer()));
        para.put(i++, new DbParameter(Types.VARCHAR, courtConfig.getFightRangeDay()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getNum()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getGroupLimit()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getUpNum()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getKeepNum()));
        para.put(i++, new DbParameter(Types.VARCHAR, courtConfig.getReward()));
        para.put(i++, new DbParameter(Types.VARCHAR, courtConfig.getRankReward()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getCourtState()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getModLimit()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getCourtId()));
        para.put(i++, new DbParameter(Types.INTEGER, courtConfig.getChannelId()));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<CricketCourtConfig> getChannelCricketConfig(List<Integer> list, int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<CricketCourtConfig> resultList = new ArrayList<>();
        String sql = "select * from t_s_cricket_court_config where channelId = ? and courtId in (" + StringUtils.listToString(list, ",") + ")";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                CricketCourtConfig data = new CricketCourtConfig();
                data.setChannelId(rs.getInt("channelId"));
                data.setCourtId(rs.getInt("courtId"));
                data.setCourtType(rs.getInt("courtType"));
                data.setCourtName(rs.getString("courtName"));
                data.setFightRangeServer(rs.getInt("fightRangeServer"));
                data.setFightRangeDay(rs.getString("fightRangeDay"));
                data.setNum(rs.getInt("num"));
                data.setGroupLimit(rs.getInt("groupLimit"));
                data.setUpNum(rs.getInt("upNum"));
                data.setKeepNum(rs.getInt("keepNum"));
                data.setReward(rs.getString("reward"));
                data.setRankReward(rs.getString("rankReward"));
                data.setCourtState(rs.getInt("courtState"));
                data.setModLimit(rs.getInt("modLimit"));
                resultList.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public List<Integer> getBatchCricketConfigId(int channelId) {
        String sql = "select courtId from t_s_cricket_court_config where channelId = ?";

        ResultSet rs = null;
        CallableStatement call = null;
        List<Integer> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                list.add(rs.getInt("courtId"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }


    public int addExchangeCodeConfig(Map<String, Object> dataMap, boolean channel) {
        String sql = "INSERT INTO `t_s_exchange_code_conf` (`batch`, `name`, `codeType`, `surrCode`, `createTime`, `startTime`, `endTime`, `channelId`,  `awards`, `maxLimit`, `receiveNum`,  `appId`, `gameType`, `slideSettings`, `serverId`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        if(channel){
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
        }
        int id = 0;
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("batch")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("name")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("codeType")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("surrCode")));
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Date()));
        para.put(i++, new DbParameter(Types.TIMESTAMP, dataMap.get("startTime")));
        para.put(i++, new DbParameter(Types.TIMESTAMP, dataMap.get("endTime")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("channelId")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("awards")));
        para.put(i++, new DbParameter(Types.BIGINT, dataMap.get("maxLimit")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("receiveNum")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("appId")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("gameType")));
        para.put(i++, new DbParameter(Types.VARCHAR, ""));
        para.put(i++, new DbParameter(Types.VARCHAR, "0"));

        PreparedStatement pstmt = null;
        try {
            pstmt = getDb().getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            for (Map.Entry<Integer, DbParameter> entry : para.entrySet()) {
                pstmt.setObject(entry.getKey(), entry.getValue().getResult());
            }
            int update = pstmt.executeUpdate();
            if(update > 0){
                ResultSet rs = pstmt.getGeneratedKeys();
                if (rs != null && rs.next()) {
                    id = rs.getInt(1);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        } finally {
            getDb().closeConnection(pstmt);
        }
        return id;
    }

    public boolean addBatchExchangeCode(List<Map<String, Object>> dataList, boolean channel) {
        String sql = "INSERT INTO `t_s_exchange_code_list` (`exchangeCode`, `configId`, `batch`, `codeNum`, `randNum`, `state`) VALUES (?,?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        if(channel){
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
        }
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> objectMap : dataList) {
            int i = 1;
            Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
            para.put(i++, new DbParameter(Types.VARCHAR, objectMap.get("exchangeCode")));
            para.put(i++, new DbParameter(Types.INTEGER, objectMap.get("configId")));
            para.put(i++, new DbParameter(Types.INTEGER, objectMap.get("batch")));
            para.put(i++, new DbParameter(Types.BIGINT, objectMap.get("codeNum")));
            para.put(i++, new DbParameter(Types.INTEGER, objectMap.get("randNum")));
            para.put(i++, new DbParameter(Types.INTEGER, 0));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateExchangeCodeState(int batchId, int state) {
        String sql = "update `t_s_exchange_code_conf` set `isEnable`=? where `batch`=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, state));
        para.put(i++, new DbParameter(Types.INTEGER, batchId));

        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean isExistExchangeCode(String rmakeCode, boolean isChannel) {
        String sql = "select surrCode from t_s_exchange_code_conf where surrCode = ?";

        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            if(isChannel){
                getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            }
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setString(i++, rmakeCode);
            rs = call.executeQuery();
            if (rs.next()) {
                return true;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);} finally {
            getDb().closeConnection(call, rs);
        }
        return false;
    }

    public boolean updateExchangeCode(Map<String, Object> dataMap) {
        String sql = "update `t_s_exchange_code_conf` set `batch`=?,`name`=?,`codeType`=?, `surrCode`=?,`startTime`=?,`endTime`=?,`channelId`=?,`awards`=?,`maxLimit`=?,`receiveNum`=?, `appId`=?,`gameType`=?  where `id`=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("batch")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("name")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("codeType")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("surrCode")));
        para.put(i++, new DbParameter(Types.TIMESTAMP, new Date()));
        para.put(i++, new DbParameter(Types.TIMESTAMP, dataMap.get("startTime")));
        para.put(i++, new DbParameter(Types.TIMESTAMP, dataMap.get("endTime")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("channelId")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("awards")));
        para.put(i++, new DbParameter(Types.BIGINT, dataMap.get("maxLimit")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("receiveNum")));
        para.put(i++, new DbParameter(Types.VARCHAR, dataMap.get("appId")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("gameType")));
        para.put(i++, new DbParameter(Types.INTEGER, dataMap.get("id")));

        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public List<Map<String, Object>> getExchangeCodeConfig(List<Integer> list, boolean isChannel) {
        if(list.isEmpty()){
            return Collections.emptyList();
        }
        ResultSet rs = null;
        CallableStatement call = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
//        String sql = "SELECT * FROM t_s_exchange_code_list ecl " +
//                "LEFT JOIN t_s_exchange_code_conf ecc on ecl.configId = ecc.id " +
//                "WHERE exchangeCode in ('" + StringUtils.listToString(list, "','") + "') order by ecl.`batch`";
        String sql = "select * from t_s_exchange_code_conf where id in (" + StringUtils.listToString(list, ",") + ") order by `batch` desc";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            if(isChannel){
                getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            }
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("batch",rs.getInt("batch"));
                dataMap.put("name",rs.getString("name"));
                dataMap.put("codeType",rs.getInt("codeType"));
                dataMap.put("surrCode",rs.getString("surrCode"));
                dataMap.put("createTime", new Date(rs.getTimestamp("createTime").getTime()));
                dataMap.put("startTime", new Date(rs.getTimestamp("startTime").getTime()));
                dataMap.put("endTime", new Date(rs.getTimestamp("endTime").getTime()));
                dataMap.put("channelId",rs.getString("channelId"));
                dataMap.put("awards",rs.getString("awards"));
                dataMap.put("maxLimit",rs.getInt("maxLimit"));
                dataMap.put("receiveNum",rs.getInt("receiveNum"));
                dataMap.put("appId",rs.getString("appId"));
                dataMap.put("gameType",rs.getInt("gameType"));
                dataMap.put("id",rs.getInt("id"));
                dataMap.put("isEnable",rs.getInt("isEnable"));
                dataMap.put("exportNum",rs.getInt("exportNum"));
                dataMap.put("maxGenerate",rs.getLong("maxGenerate"));
//                dataMap.put("exchangeCode", rs.getString("exchangeCode"));
                resultList.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public List<Map<String, Object>> getExchangeCodeConfig(int batchId, boolean isChannel) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
        String sql = "select * from t_s_exchange_code_conf where batch = ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            if(isChannel){
                getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            }
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, batchId);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("batch",rs.getInt("batch"));
                dataMap.put("name",rs.getString("name"));
                dataMap.put("codeType",rs.getInt("codeType"));
                dataMap.put("surrCode",rs.getInt("surrCode"));
                dataMap.put("createTime", new Date(rs.getTimestamp("createTime").getTime()));
                dataMap.put("startTime", new Date(rs.getTimestamp("startTime").getTime()));
                dataMap.put("endTime", new Date(rs.getTimestamp("endTime").getTime()));
                dataMap.put("channelId",rs.getString("channelId"));
                dataMap.put("awards",rs.getString("awards"));
                dataMap.put("maxLimit",rs.getInt("maxLimit"));
                dataMap.put("receiveNum",rs.getInt("receiveNum"));
                dataMap.put("appId",rs.getString("appId"));
                dataMap.put("gameType",rs.getInt("gameType"));
                dataMap.put("id",rs.getInt("id"));
                dataMap.put("isEnable",rs.getInt("isEnable"));
                dataMap.put("exportNum",rs.getInt("exportNum"));
                dataMap.put("maxGenerate",rs.getLong("maxGenerate"));
                resultList.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public List<Map<String, Object>> getExchangeCodeConfig(String channel, boolean isChannel) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
//        String sql = "SELECT * FROM t_s_exchange_code_list ecl " +
//                "LEFT JOIN t_s_exchange_code_conf ecc on ecl.configId = ecc.id " +
//                "WHERE ecc.channelId = ? order by ecl.`batch`";
        String sql = "select * from t_s_exchange_code_conf where channelId = ? order by `batch` desc";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            if(isChannel){
                getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            }
            call = getDb().getConnection().prepareCall(sql);
            call.setString(1, channel);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("batch",rs.getInt("batch"));
                dataMap.put("name",rs.getString("name"));
                dataMap.put("codeType",rs.getInt("codeType"));
                dataMap.put("surrCode",rs.getString("surrCode"));
                dataMap.put("createTime", new Date(rs.getTimestamp("createTime").getTime()));
                dataMap.put("startTime", new Date(rs.getTimestamp("startTime").getTime()));
                dataMap.put("endTime", new Date(rs.getTimestamp("endTime").getTime()));
                dataMap.put("channelId",rs.getString("channelId"));
                dataMap.put("awards",rs.getString("awards"));
                dataMap.put("maxLimit",rs.getInt("maxLimit"));
                dataMap.put("receiveNum",rs.getInt("receiveNum"));
                dataMap.put("appId",rs.getString("appId"));
                dataMap.put("gameType",rs.getInt("gameType"));
                dataMap.put("id",rs.getInt("id"));
                dataMap.put("isEnable",rs.getInt("isEnable"));
                dataMap.put("exportNum",rs.getInt("exportNum"));
                dataMap.put("maxGenerate",rs.getLong("maxGenerate"));
//                dataMap.put("exchangeCode", rs.getString("exchangeCode"));
                resultList.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public List<Map<String, Object>> getExchangeCodeConfig2(String channel, int batchId, boolean isChannel) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
//        String sql = "SELECT * FROM t_s_exchange_code_list ecl " +
//                "LEFT JOIN t_s_exchange_code_conf ecc on ecl.configId = ecc.id " +
//                "WHERE ecc.channelId = ? and ecl.batch = ? ";
        String sql = "select * from t_s_exchange_code_conf where channelId = ?  and batch = ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            if(isChannel){
                getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            }
            call = getDb().getConnection().prepareCall(sql);
            call.setString(1, channel);
            call.setInt(2, batchId);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("batch",rs.getInt("batch"));
                dataMap.put("name",rs.getString("name"));
                dataMap.put("codeType",rs.getInt("codeType"));
                dataMap.put("surrCode",rs.getInt("surrCode"));
                dataMap.put("createTime", new Date(rs.getTimestamp("createTime").getTime()));
                dataMap.put("startTime", new Date(rs.getTimestamp("startTime").getTime()));
                dataMap.put("endTime", new Date(rs.getTimestamp("endTime").getTime()));
                dataMap.put("channelId",rs.getString("channelId"));
                dataMap.put("awards",rs.getString("awards"));
                dataMap.put("maxLimit",rs.getInt("maxLimit"));
                dataMap.put("receiveNum",rs.getInt("receiveNum"));
                dataMap.put("appId",rs.getString("appId"));
                dataMap.put("gameType",rs.getInt("gameType"));
                dataMap.put("id",rs.getInt("id"));
                dataMap.put("isEnable",rs.getInt("isEnable"));
                dataMap.put("exportNum",rs.getInt("exportNum"));
                dataMap.put("maxGenerate",rs.getLong("maxGenerate"));
//                dataMap.put("exchangeCode", rs.getString("exchangeCode"));
                resultList.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public List<Map<String, Object>> getExchangeCodeUser(int batchId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
        String sql = "SELECT ecu.userId,ecu.useTime, ecl.batch,ecl.exchangeCode,ecl.configId FROM t_s_exchange_code_list ecl " +
                "LEFT JOIN t_s_exchange_code_use ecu on ecl.configId = ecu.configId and ecl.exchangeCode = ecu.exchangeCode " +
                "WHERE ecl.batch = ? ";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, batchId);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("batch",rs.getInt("batch"));
                dataMap.put("userId",rs.getLong("userId"));
                dataMap.put("receiveTime",rs.getLong("useTime"));
                dataMap.put("configId",rs.getInt("configId"));
                dataMap.put("code", rs.getString("exchangeCode"));
                resultList.add(dataMap);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return resultList;
    }

    public boolean batchAddInnerUser(List<Map<String, Object>> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "replace into `t_s_inner_user_black`(userId,serverId,channelId,openId,`remark`) values (?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, map.get("userId")));
            para.put(i++, new DbParameter(Types.BIGINT, map.get("serverId")));
            para.put(i++, new DbParameter(Types.BIGINT, map.get("channelId")));
            para.put(i++, new DbParameter(Types.VARCHAR, map.get("openId")));
            para.put(i++, new DbParameter(Types.VARCHAR, map.get("remark")));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean deleteInnerUser(List<Long> channelIdList) {
        String sql = "delete from `t_s_inner_user_black` where userId in (" + StringUtils.listToString(channelIdList, ",") + ")";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    public boolean batchInsertShieldMallMarkIdData(List<ShieldMallMarkIdData> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
        String sql = "insert into `t_s_shield_mall_markid`(`channelId`, `mallMarkId`, `mallName`, `state`, `goodsType`, `remark`) values (?,?,?,?,?,?)";

        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ShieldMallMarkIdData data: list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMallMarkId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getMallName()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGoodsType()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRemark()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean batchUpdateShieldMallMarkIdData(List<ShieldMallMarkIdData> list) {

        if (list.size() == 0) {
            return false;
        }

        boolean result = false;
//        String sql = "update `t_s_shield_mall_markid` set `mallName`=?,`state`=? where `channelId`=? and `mallMarkId`=?";
        String sql = "update `t_s_shield_mall_markid` set  `state`=?, `remark`=? where `channelId`=? and `mallMarkId`=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ShieldMallMarkIdData data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
//            para.put(i++, new DbParameter(Types.VARCHAR, data.getMallName()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getState()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRemark()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMallMarkId()));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean deleteShieldMallMarkIdData(int channelId, int goodsId) {
        String sql = "delete from t_s_shield_mall_markid where mallMarkId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
        para.put(i++, new DbParameter(Types.INTEGER, goodsId));
        para.put(i++, new DbParameter(Types.INTEGER, channelId));
        if (getDb().executeNoneQuery(sql, para) > 0) {
            return true;
        }
        return false;
    }

    /**
     * 更新页签公告
     *
     * @param tabNoticeList 页签公告 包括简体和繁体
     * @return boolean
     */
    public boolean batchUpdateChannelTabNotice(List<ChannelTabNotice> tabNoticeList) {
        boolean res = false;

        String sql = "replace into `t_s_tab_notice`(channelId,gameType,language,appId,tabNotices) values (?,?,?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ChannelTabNotice channelTabNotice : tabNoticeList) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, channelTabNotice.getChannelId()));
            para.put(i++, new DbParameter(Types.INTEGER, channelTabNotice.getGameType()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelTabNotice.getLanguage()));
            para.put(i++, new DbParameter(Types.VARCHAR, channelTabNotice.getAppId()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(channelTabNotice.getTabNotices())));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            res = true;
        }

        return res;
    }

    public boolean batchInsertAccountWhiteList(List<WhiteAccount> accounts) {
        String sql = "insert into t_s_platform_userId(platformUserId,remark) values (?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (WhiteAccount account  : accounts) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, account.getPlatformUserId()));
            para.put(i, new DbParameter(Types.VARCHAR, account.getRemark()));
            mapList.add(para);
        }

        return getDb().executeBatchQuery(sql, mapList) > -1;
    }

    public boolean updateAccountWhiteList(WhiteAccount whiteAccount) {
        String sql = "update t_s_platform_userId set platformUserId=?,remark=? where id=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.VARCHAR, whiteAccount.getPlatformUserId()));
        para.put(i++, new DbParameter(Types.VARCHAR, whiteAccount.getRemark()));
        para.put(i, new DbParameter(Types.INTEGER, whiteAccount.getId()));

        return getDb().executeNoneQuery(sql, para) > 0;
    }

    public boolean deleteAccountWhiteList(int id) {
        String sql = "delete from t_s_platform_userId where id=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(1, new DbParameter(Types.INTEGER, id));

        return getDb().executeNoneQuery(sql, para) > 0;
    }

    public boolean batchInsertIPWhiteList(List<WhiteIP> ips) {
        String sql = "insert into t_s_white_ip(content,remark,type) values (?,?,?)";
        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (WhiteIP ip  : ips) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, ip.getContent()));
            para.put(i++, new DbParameter(Types.VARCHAR, ip.getRemark()));
            para.put(i, new DbParameter(Types.INTEGER, 0)); // IP白名单类型
            mapList.add(para);
        }

        return getDb().executeBatchQuery(sql, mapList) > -1;
    }

    public boolean updateIPWhiteList(WhiteIP ip) {
        String sql = "update t_s_white_ip set content=?,remark=? where id=?";

        getDb().setConnName(DbNameStrategy.getServerDb());
        int i = 1;
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(i++, new DbParameter(Types.VARCHAR, ip.getContent()));
        para.put(i++, new DbParameter(Types.VARCHAR, ip.getRemark()));
        para.put(i, new DbParameter(Types.VARCHAR, ip.getId()));

        return getDb().executeNoneQuery(sql, para) > 0;
    }

    public boolean deleteIPWhiteList(int id) {
        String sql = "delete from t_s_white_ip where id=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        Map<Integer, DbParameter> para = new HashMap<>();
        para.put(1, new DbParameter(Types.INTEGER, id));

        return getDb().executeNoneQuery(sql, para) > 0;
    }

    public boolean batchDeleteShieldMallMarkIdData(int channelId, List<Integer> goodsIdList) {
        boolean result = false;
        String sql = "delete from t_s_shield_mall_markid where mallMarkId=? and channelId=?";
        getDb().setConnName(DbNameStrategy.getServerDb());
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (int goodsId : goodsIdList) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, goodsId));
            para.put(i++, new DbParameter(Types.INTEGER, channelId));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
